package com.wp.land.api;

import com.wp.land.context.VDataContext;
import com.wp.land.entity.CityLandData;
import com.wp.land.entity.GDData;
import com.wp.land.entity.Rainfall;
import com.wp.land.entity.Scoring;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: zhou
 * @Description:
 * @Date:Create in 2019/04/28
 * @Modified By:
 */
@RestController
@RequestMapping("/api/")
public class ApiTestData{

    public static int count_1 = 0;



    public static List<GDData> list_1 = new ArrayList<GDData>(){{

        add(new GDData("武汉","3093000"));
        add(new GDData("十堰","2556150"));
        add(new GDData("荆州","6940350"));

        add(new GDData("宜昌","3454650"));
        add(new GDData("襄阳","6505800"));
        add(new GDData("荆门","3819750"));

        add(new GDData("孝感","3909600"));
        add(new GDData("黄冈","5004300"));
        add(new GDData("咸宁","2320050"));

        add(new GDData("随州","2062800"));
        add(new GDData("其它","9953550"));
    }};

    @RequestMapping(value = "/getData_1", method = RequestMethod.GET)
    public Object getData_1(String uid) {
        List listData = new ArrayList(16);

        listData.add(new GDData("武汉","3093000"));
        listData.add(new GDData("十堰","2556150"));
        listData.add(new GDData("荆州","6940350"));

        listData.add(new GDData("宜昌","3454650"));
        listData.add(new GDData("襄阳","6505800"));
        listData.add(new GDData("荆门","3819750"));

        listData.add(new GDData("孝感","3909600"));
        listData.add(new GDData("黄冈","5004300"));
        listData.add(new GDData("咸宁","2320050"));

        listData.add(new GDData("随州","2062800"));
        listData.add(new GDData("其它","9953550"));
        listData.add(new GDData("武汉","3093000"));

        listData.add(new GDData("十堰","2556150"));
        listData.add(new GDData("荆州","6940350"));
        listData.add(new GDData("宜昌","3454650"));

        List listReturn = new ArrayList(16);
        int temp = count_1 + 5;

        if (temp > 13){
            count_1 = 0;
        }
        for (int i = count_1; i <=listData.size() && i< count_1 + 5; i++) {
            listReturn.add(listData.get(i));
        }
        count_1 = count_1 + 3;
        return listReturn;
    }


    @RequestMapping(value = "/getData_2", method = RequestMethod.GET)
    public Object getData_2(){

        int onceSum = 5;
        int next = 3;
        String key = "1";

        List listReturn = new ArrayList(16);

        List cacheList = (List) VDataContext.getValue(key,VDataContext.list_1);
        //返回数据
        for (int i = 0; i < onceSum; i++) {
            listReturn.add(cacheList.get(i));
        }
        //删除
        for (int i = 0; i < next; i++) {
            GDData gdData = (GDData) cacheList.get(0);
            cacheList.remove(0);
            cacheList.add(gdData);
        }

        System.out.println(VDataContext.list_1);

        VDataContext.setValue(key,cacheList);

        return listReturn;
    }


    @RequestMapping(value = "/getcityscore", method = RequestMethod.GET)
    public Object getCtiyScoreData(){

        int onceSum = 5;
        int next = 3;
        String key = "score";

        List listReturn = new ArrayList(16);

        List cacheList = (List) VDataContext.getValue(key,VDataContext.list_Scoring);
        //返回数据
        for (int i = 0; i < onceSum; i++) {
            listReturn.add(cacheList.get(i));
        }
        //删除
        for (int i = 0; i < next; i++) {
            Scoring scoring = (Scoring) cacheList.get(0);
            cacheList.remove(0);
            cacheList.add(scoring);
        }

        System.out.println(VDataContext.list_Scoring);

        VDataContext.setValue(key,cacheList);

        return listReturn;
    }

    /**
     *  降雨量
     * @return
     */
    @RequestMapping(value = "/getRainfall", method = RequestMethod.GET)
    public Object getRainfall(){

        int onceSum = 5;
        int next = 3;
        String key = "rainfall";

        List listReturn = new ArrayList(16);

        List cacheList = (List) VDataContext.getValue(key,VDataContext.list_Rainfall);
        //返回数据
        for (int i = 0; i < onceSum; i++) {
            listReturn.add(cacheList.get(i));
        }
        //删除
        for (int i = 0; i < next; i++) {
            Rainfall rainfall = (Rainfall) cacheList.get(0);
            cacheList.remove(0);
            cacheList.add(rainfall);
        }

        System.out.println(VDataContext.list_Rainfall);

        VDataContext.setValue(key,cacheList);

        return listReturn;
    }

    /**
     *  耕地占比
     * @return
     */
    @RequestMapping(value = "/getLand", method = RequestMethod.GET)
    public Object getLand(){

        int onceSum = 4;
        int next = 2;
        String key = "land";

        List listReturn = new ArrayList(16);

        List cacheList = (List) VDataContext.getValue(key,VDataContext.list_Land);
        //返回数据
        for (int i = 0; i < onceSum; i++) {
            listReturn.add(cacheList.get(i));
        }
        //删除
        for (int i = 0; i < next; i++) {
            Object rainfall = cacheList.get(0);
            cacheList.remove(0);
            cacheList.add(rainfall);
        }

        System.out.println(VDataContext.list_Land);

        VDataContext.setValue(key,cacheList);

        return listReturn;
    }


    /**
     *  各地农作物面积
     * @return
     */
    @RequestMapping(value = "/getCrapArea", method = RequestMethod.GET)
    public Object getCrapArea(){

        int onceSum = 20;
        int next = 20;
        String key = "crapArea";

        List listReturn = new ArrayList(16);

        List cacheList = (List) VDataContext.getValue(key,VDataContext.list_CrapArea);
        //返回数据
        for (int i = 0; i < onceSum; i++) {
            listReturn.add(cacheList.get(i));
        }
        //删除
        for (int i = 0; i < next; i++) {
            Object rainfall = cacheList.get(0);
            cacheList.remove(0);
            cacheList.add(rainfall);
        }

        System.out.println(VDataContext.list_CrapArea);

        VDataContext.setValue(key,cacheList);

        return listReturn;
    }

    /**
     *  获取城市土地类型信息
     * @return
     */
    @RequestMapping(value = "/city/{part}/{id}", method = RequestMethod.GET)
    public Object getCityLandData_1(@PathVariable String id){
        List listReturn = new ArrayList(16);
        CityLandData cityLandData = VDataContext.list_CityLandData.get(VDataContext.citys);
        Map params = new HashMap(16);

        if (id.equals("11")){
            params.put("value",cityLandData.get_1LandName()+"占比");
        }else if (id.equals("12")){
            params.put("value",cityLandData.get_1Land_2());
        }else if (id.equals("13")){
            params.put("value",cityLandData.get_1Land_3());
            params.put("name",cityLandData.get_1LandName());
        }else if (id.equals("14")){
            params.put("name","");
            params.put("value",cityLandData.get_1Land_4());
        }

        //第2部分
        else if (id.equals("21")){
            params.put("value",cityLandData.get_1LandName()+"概述");
        }else if (id.equals("22")){
            return cityLandData.get_2list();
        }else if (id.equals("23")){
            params.put("value",cityLandData.get_2Land_2());
        }

        //第3部分
        else if (id.equals("31")){
            return cityLandData.get_3list();
        }else if (id.equals("32")){
            params.put("value",cityLandData.get_3Land_3());
        }

        //第4部分
        else if (id.equals("41")){
            params.put("value",cityLandData.get_4Land_1());
        }else if (id.equals("42")){
            params.put("value",cityLandData.get_4Land_2());
        }else if (id.equals("43")){
            return cityLandData.get_4list();
        }

        //第5部分
        else if (id.equals("51")){
            params.put("name","");
            params.put("value",cityLandData.get_5Land_1());
        }else if (id.equals("52")){
            params.put("name","");
            params.put("value",cityLandData.get_5Land_2());
        }else if (id.equals("53")){
            params.put("name","");
            params.put("value",cityLandData.get_5Land_3());
        }else if (id.equals("54")){
            params.put("name","");
            params.put("value",cityLandData.get_5Land_4());
        }else if (id.equals("55")){
            params.put("name","");
            params.put("value",cityLandData.get_5Land_5());
        }else if (id.equals("56")){
            params.put("name","");
            params.put("value",cityLandData.get_5Land_6());
        }

        //第6部分
        else if (id.equals("61")){
            params.put("url","");
            params.put("value",cityLandData.get_6Land_1());
        }else if (id.equals("62")){
            //TODO
            return cityLandData.get_6list();
        }else if (id.equals("63")){
            params.put("name","");
            params.put("value",cityLandData.get_6land_3());
        } else if (id.equals("64")){
            params.put("name","");
            params.put("value",cityLandData.get_6land_4());
        }

        listReturn.add(params);
        return listReturn;
    }

    /**
     *  获取城市土地类型信息 2 部分
     * @return
     */
    @RequestMapping(value = "/city/21/1/{id}", method = RequestMethod.GET)
    public Object getCityLandData_2(@PathVariable String id){
        List listReturn = new ArrayList(16);
        CityLandData cityLandData = VDataContext.list_CityLandData.get(VDataContext.citys);
        Map params = new HashMap(16);
        if (id.equals("21")){
            params.put("value",cityLandData.get_1LandName()+"占比");
        }else if (id.equals("22")){
            params.put("value",cityLandData.get_2Land_2());
        }
        listReturn.add(params);
        return listReturn;
    }

}
